package com.andnnl.template;

import java.util.List;
import java.util.Map;

import com.andnnl.template.param.BaseParamConfig;


public class ParamTemplate {
    int gwNum;//网关号
    String template;//模板
    String jsonConfig;//模板校验规则json
    // String description;//模板描述
    List<String> paramNameList;//参数名列表，按顺序
    Map<String, BaseParamConfig> paramMap;//参数配置
    String[] templatePart;//用模板参数分隔后的内容列表
    
    public ParamTemplate(String template, String jsonConfig,List<String> paramNameList, Map<String, BaseParamConfig> paramMap,String[] templatePart) {
        this.template = template;
        this.jsonConfig = jsonConfig;
        this.paramNameList=paramNameList;
        this.paramMap = paramMap;
        this.templatePart = templatePart;
    }
    
    // public String getDescription() {
    //     return description;
    // }
    // public void setDescription(String description) {
    //     this.description = description;
    // }
    public Map<String, BaseParamConfig> getParamMap() {
        return paramMap;
    }
    public void setParamMap(Map<String, BaseParamConfig> paramMap) {
        this.paramMap = paramMap;
    }
    public int getGwNum() {
        return gwNum;
    }
    public void setGwNum(int gwNum) {
        this.gwNum = gwNum;
    }
    public String getTemplate() {
        return template;
    }
    public void setTemplate(String template) {
        this.template = template;
    }
    public String getJsonConfig() {
        return jsonConfig;
    }
    public void setJsonConfig(String jsonConfig) {
        this.jsonConfig = jsonConfig;
    }
    public List<String> getParamNameList() {
        return paramNameList;
    }
    public void setParamNameList(List<String> paramNameList) {
        this.paramNameList = paramNameList;
    }
    public String[] getTemplatePart() {
        return templatePart;
    }
    public void setTemplatePart(String[] templatePart) {
        this.templatePart = templatePart;
    }

    /**
     * 生成短信内容
     * @return
     */
    public String genMsg() {
        String msg = template;
        for (String paramName : paramNameList) {
            BaseParamConfig paramConfig = paramMap.get(paramName);
            if (paramConfig != null) {
                String paramValue = paramConfig.generateValue();
                msg = msg.replace("${" + paramName + "}", paramValue);
            }
        }
        return msg;
    }
}
